package com.msunsoft.system.controller;

import java.util.List;

import javax.annotation.Resource;

import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.msunsoft.common.ReponseBodyVo;
import com.msunsoft.system.mybatis.model.SysRole;
import com.msunsoft.system.service.impl.RoleService;
import com.msunsoft.system.vo.RoleVo;

@Controller
@RequestMapping(value = "/role")
public class RoleAdminController {

    @Resource
    private RoleService roleService;

    @RequestMapping("")
    @RequiresPermissions("sys:role:view")
    public String index(){
        return "admin/role/role";
    }

    @ResponseBody
    @RequestMapping("/list-paged")
    @RequiresAuthentication
    public List<RoleVo> listPaged(){
        List<RoleVo> info = this.roleService.listAllPaged ();
        return info;
    }

    /**
     * 用于用户管理时, 查询所有角色
     * 
     * @return 所有角色
     */
    @ResponseBody
    @RequestMapping("/list-all")
    @RequiresAuthentication
    public List<SysRole> list(){
        return this.roleService.listAll ();
    }

    @RequestMapping(value = "/insert",method = RequestMethod.POST)
    @ResponseBody
    @RequiresPermissions("sys:role:insert")
    public ReponseBodyVo insert(@RequestBody RoleVo role){
        this.roleService.insert (role);
        return new ReponseBodyVo ("成功","插入角色成功.");
    }

    @RequestMapping(value = "/edit-by-id",method = RequestMethod.POST)
    @ResponseBody
    @RequiresPermissions("sys:role:edit")
    public ReponseBodyVo update(@RequestBody RoleVo vo){
        this.roleService.updateById (vo);
        return new ReponseBodyVo ("成功","修改角色成功.");
    }

    @RequestMapping(value = "/del-by-id")
    @ResponseBody
    @RequiresPermissions("sys:role:del")
    public ReponseBodyVo deleteById(Integer id){
        this.roleService.deleteRoleById (id);
        return new ReponseBodyVo ("成功","删除角色成功.");
    }
}
